    //
//  CustomUIActionSheetViewControllerNxib.m
//  iStock Global
//
//  Created by Andy on 2010/10/13.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CustomUIActionSheetViewControllerNxib.h"
#import <QuartzCore/QuartzCore.h>
@implementation CustomUIActionSheetViewControllerNxib
@synthesize actionSheetView;
@synthesize delgete;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

 
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	[self slideIn];		
}
 
- (void)slideIn {
	/*設計原理
	  分成兩個view
	  第一view 為self.view 主要為底色 模糊背面
	  第二view 為控制元件放上去的view 
	 */ 
	
	//第一view 為self.view 主要為底色 模糊背面
	UIView *mainview;
	mainview=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
	self.view=mainview;
	[mainview release];
    
    self.view.backgroundColor=[UIColor lightTextColor];
	
    //=====================================
	
	//第二view 為控制元件放上去的view 
	CGRect frame = self.view.frame;
    frame.origin = CGPointMake(60,0);
	frame=CGRectMake(60, 50,200, 150);
	//=============================
	
	//將uiview 的四個角弄成有弧度 另外要加入 #import <QuartzCore/QuartzCore.h>
	UIView *_temp=[[UIView alloc] initWithFrame:frame];
    self.actionSheetView=_temp;
    [_temp release];
	self.actionSheetView.layer.cornerRadius=10;	
	self.actionSheetView.layer.masksToBounds = YES;
	self.actionSheetView.layer.shadowColor=[UIColor whiteColor].CGColor;
	self.actionSheetView.layer.shadowOpacity=2.0;
	self.actionSheetView.layer.shadowRadius=5.0;
	self.actionSheetView.layer.shadowOffset=CGSizeMake(0, 3);
	self.actionSheetView.clipsToBounds=NO;
	self.actionSheetView.backgroundColor=[UIColor redColor];	
	

	[self.view addSubview:self.actionSheetView];
	//=====================================================================
	
	//增加控制物件
	UIButton * headerbutton = [[[UIButton alloc] initWithFrame:CGRectZero] autorelease];
	CGRect buttonframe=headerbutton.frame;
	buttonframe.origin.x=30;
	buttonframe.origin.y=30;
	buttonframe.size.height=30;
	buttonframe.size.width=60;
	headerbutton.frame = buttonframe;
	
	[headerbutton addTarget:self action:@selector(slideOut) forControlEvents:UIControlEventTouchUpInside];
	headerbutton.backgroundColor = [UIColor blackColor];
	headerbutton.titleLabel.font= [UIFont boldSystemFontOfSize:10];
	[headerbutton  setTitle:@"ff" forState:UIControlStateNormal  ];	
	
	[self.actionSheetView addSubview:headerbutton];
	//============
	
	//動畫設定
    [UIView beginAnimations:@"presentWithSuperview" context:nil];
    frame.origin = CGPointMake(60.0,  150);
	self.actionSheetView.frame = frame;
	[UIView setAnimationCurve:UIViewAnimationCurveLinear];
	[UIView setAnimationDuration:5000];
    [UIView commitAnimations];
	//=======
}

- (void) slideOut {
	
	 [self.delgete button_CustomUIActionDelgeteNxib];
	
	//do what you need to do with information gathered from the custom action sheet. E.g., apply data filter on parent view.
	
	[UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];
	
    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
	
    // Move this view to bottom of superview
    CGRect frame = self.actionSheetView.frame;
    frame.origin = CGPointMake(60.0, 50);
    self.actionSheetView.frame = frame;
	[UIView commitAnimations]; 
}

// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [self.view removeFromSuperview];
    }
}





/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[actionSheetView release];
    [super dealloc];
}


@end
